package com.thread.thread;

/**
 * @author wangyingjie
 * @date
 * @remark
 */
public class MyThread_4 extends Thread {

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println(getName()+"优先级是===>"+getPriority());
            if (i == 20) {
                Thread.yield();
            }
        }
    }

    public static void main(String[] args) {//主线程
        Thread.currentThread().setPriority(6);
        MyThread_4 t1 = new MyThread_4();
        System.out.println(t1.getPriority());//由主线程创建的子线程默认都是继承主线程的优先级
        t1.start();
        t1.setPriority(MAX_PRIORITY);
        for (int i = 0; i < 100; i++) {
            System.out.println(currentThread().getName());
            if (i == 20){
                MyThread_4 t2 = new MyThread_4();
                System.out.println(t2.getPriority());
                t2.start();
                t2.setPriority(MIN_PRIORITY);
            }
        }
    }
}
